#ifndef HUFFMAN
#define HUFFMAN

typedef struct huff_code_struct {
  int length;
  long long bits;
} *huff_code;

typedef struct huff_node_struct {
  int w;
  int c;
  struct huff_node_struct *father;
  struct huff_node_struct *left;
  struct huff_node_struct *right;
  int gdbh_index;
} *huff_node;

typedef struct huff_tree_struct {
  huff_node root;
  huff_node special;
  huff_node chars[256];
  huff_node gdbh[512];
  int count;
} huff_tree;
extern huff_tree thetree;

void huff_code_tostring (huff_code this);
huff_node huff_node_new ();
void huff_node_init (huff_node this, int w, int c, huff_node f, huff_node l, huff_node r, int i);
void huff_node_tostring (huff_node this);
void _huff_tree_tostring (huff_node n, int depth, long mask);
void huff_tree_tostring ();
int huff_node_isgdbh (huff_node this);
huff_node huff_node_eob (huff_node this);
void huff_tree_update (huff_node q);
void huff_tree_modify (int c);
void huff_node_get_code (huff_node this, huff_code res);
void huff_tree_init (int c);
int huff_getcode (int c, huff_code res);
void huff_special_code (huff_code res);
int huff_node_isspecial (huff_node this);
int huff_node_isleaf (huff_node this);

#endif
